//* steal nearby credits, otherwise its harmless

alien_stealer_images = new Images('stealer',1);

function AlienStealer() {
  // contructor
  var that = new Alien();
  that.images = alien_stealer_images;
  that.shrapnel = 0;
  that.credit = 0;
  that.dx = 2*(Math.random()-Math.random()); 
  that.dy = 2*(Math.random()-Math.random());
  that.target = -1;
  that.strength = 0;
  that.max_speed = 5;
  that.life = 1000;  
  
  // update dummy
  that.update = function() {
    this.constraint(500);
    // point to first credit
    if (credits.credits.length > 0) {
      // folow choosen credit
      if ( (this.target > 0)&&(this.target < credits.credits.length-1) ) {
        var xx = (credits.credits[this.target].x-this.x);
        var yy = (credits.credits[this.target].y-this.y);
        var d = Math.sqrt(xx*xx+yy*yy);  
        this.dx = this.max_speed*xx/d;
        this.dy = this.max_speed*yy/d;
        // actually steal that near credit
        if ( d <= 30 ) {
          credits.credits.splice(this.target,1);
          if (Math.random() > 0.5)
            this.credit++;
        } 
      } else {
        // choose some credit and follow it until it dissapear, then choose another credit
        this.target = Math.floor(Math.random()*(credits.credits.length-1));
      }
    }
    // move dummy
    this.simpleMove();
  }
 
  return that;
}

function AlienStealers(ACount) {
  // create aliens
  var that = new Array();
  for (var i=0; i<ACount; i++)
      that.push(new AlienStealer());
  return that;  
}
